package thread3;

import java.util.Scanner;

public class Test2 {
    public static Object object = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            while (true) {
                synchronized (object) {
                    System.out.println("请输入一个整数:");
                    int a = scanner.nextInt();
                    System.out.println("a: " + a);
                }
            }
        });
        thread1.start();

        Thread.sleep(2000);

        Thread thread2 = new Thread(() -> {
            synchronized (object) {
                System.out.println("hello thread2");
            }
        });
        thread2.start();
    }
}
